package cn.wgx.commons.util;


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;

/**
 * 短信发送
 */
public class SMSSender {
// 大于0的数字	提交成功
//–1	账号未注册
//–2	其他错误
//–3	帐号或密码错误
//–5	余额不足，请充值
//–6	定时发送时间不是有效的时间格式
//-7	提交信息末尾未签名，请添加中文的企业签名【 】
//–8	发送内容需在1到300字之间
//-9	发送号码为空
//-10	定时时间不能小于系统当前时间
//-100	IP黑名单
//-102	账号黑名单
//-103	IP未导白
//https://sdk2.028lk.com/utf8/BatchSend2.aspx?CorpID=CDJS004418&Pwd=zm0513@&Mobile=15534066521&Content=%E6%92%92%E6%97%A6%E6%92%92%E6%97%A6asd%E9%98%BF%E8%90%A8%E5%BE%B7%E5%95%8A%E5%95%8A%E5%B2%81%E7%9A%84%E9%9C%80%E8%B1%86%E8%85%90%E5%B9%B2%E5%9C%B0%E6%96%B9%E4%B8%AA

    private static String ACCOUNT = "CDJS004418";

    private static String PASSWORD = "zm0513@";

    private static String SMS_SEND_URL = "https://sdk2.028lk.com/utf8/BatchSend2.aspx";

    private static String encodeType = "MD5";

    private static MessageDigest md;

    private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();


    /**
     * http://47.93.161.228:8080/eums/sms/utf8/send.do?name=test&seed=20130806102030&key=cd6e1aa6b89e8e413867b33811e70153&dest=13800138000,13012345678&content=test123
     * @param phoneNum
     * @param sms
     * @return
     */
    public static Integer sendSms(String phoneNum, String sms){
        try {
            sms = URLEncoder.encode(sms, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        StringBuffer sb = new StringBuffer(getUrlParamKey());
        sb.append("&Mobile="+phoneNum);
        sb.append("&Content="+sms);
        String res = HttpRequest.sendPost(SMS_SEND_URL, sb.toString());
        try {
            Integer r = Integer.parseInt(res);
            return r;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return 0;
    }


    private static String getUrlParamKey(){
        StringBuffer sb = new StringBuffer();
        sb.append("CorpID="+ACCOUNT);
        sb.append("&Pwd="+PASSWORD);
        return sb.toString();
    }

    public static String a = "您正在登录中科北影移动办公系统，验证码为：3151，请勿泄漏验证码。如非本人操作，请联系我们010-64128837。[中科北影]";
    public static void main(String aaaa[]){
        String aa = "您正在登录中科北影移动办公系统，验证码为：3151，请勿泄漏验证码。如非本人操作，请联系我们010-64128837。[中科北影]";
        try {
            String b = new String(aa.getBytes("utf8"),"utf8");

            //System.out.println(sendSms("15034421480",URLEncoder.encode(b, "UTF-8")));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

}
